function EPSC_TrainSummary()
%
global CONTROL

clist = {'rs', 'y+', 'g^', 'bo', 'c.'};
llist = {'-', '--', '-.-'};
face = {'w', 'k'}
sf = getmainselection;
cells = {CONTROL(sf).filename};
uc = unique(cells);
celltypes = {CONTROL(sf).CellType};
uct = unique(celltypes);

hf = newfigure('EPSC Train Summary', 'Summary');

no = zeros(length(sf), 1);
endamp = no;
endss = no;
DR = no;
PR = no;
sslow = no;
index = no;
    i = 1;
    for k = sf
        pro = CONTROL(k).protocol;
        par = CONTROL(k).Parameters;

        r = make_struct(par, 'delay 5, np 20, freq 20, tau_init 40, nrep 4');
        freq(i) = r.freq;
        tau_init = r.tau_init;
        nrep = r.nrep;
        np = r.np;
        delay = r.delay;

        ET=CONTROL(k).EPSC_Train;
        if(~isempty(ET))
            endamp(i) =  mean(mean(ET.amps(:,end-5:end)));
            endss(i) = mean(mean(ET.slowamp(:, end-5:end)));
            DR(i) =endamp(i)/mean(mean(ET.amps(:,1)));
            PR(i) = mean(mean(ET.amps(:,2)))/mean(mean(ET.amps(:,1)));
            tau(i) = ET.fitpar(3);
            ssslow(i) = endss(i)/(endamp(i)+endss(i));
            no(i) = find(strcmpi(cells{i}, uc) == 1);
            index(i) = k;
            if(i == sf(1))
                fprintf (1, 'No., File, Record, CellType, Freq, DR, PR, Tau, Slow\n');
            end;
            [p, f] = fileparts(CONTROL(k).filename);
            fprintf(1, '%d: f_%s,%d,%s,%6.0f,%7.2f,%7.2f,%7.3f,%7.3f\n', ...
                no(i), f, CONTROL(k).recbeg, CONTROL(k).CellType, ...
                freq(i), DR(i), PR(i), tau(i), ssslow(i));
        else
            %       fprintf(1, '%s,%d\n', CONTROL(i).filename, CONTROL(i).recbeg);
        end;
        i = i + 1;
    end;

    subplot(2,2,1);
    for i = 1: max(no)
        im = mod(i-1, max(no)-1)+1;
        ilist = find(no == i);
        m = find(strcmpi(CONTROL(sf(ilist(1))).CellType, uct));
        [x, isort] = sort(freq(ilist));
        j = ilist(isort);
        plot(freq(j), DR(j), clist{im}, 'linestyle', llist{m}, 'markerfacecolor', face{m});
        hold on;
    end;
    ylabel('DR');
    xLabel('freq (Hz)')

    subplot(2,2,2);
    for i = 1: max(no)
        im = mod(i-1, max(no)-1)+1;
        ilist = find(no == i);
        m = find(strcmpi(CONTROL(sf(ilist(1))).CellType, uct));
        [x, isort] = sort(freq(ilist));
        j = ilist(isort);
        plot(freq(j), PR(j), clist{im}, 'linestyle', llist{m}, 'markerfacecolor', face{m});
        hold on;
    end;
    ylabel('PR');
    xLabel('freq (Hz)')
    subplot(2,2,3);
    for i = 1: max(no)
        im = mod(i-1, max(no)-1)+1;
        ilist = find(no == i);
        m = find(strcmpi(CONTROL(sf(ilist(1))).CellType, uct));
        [x, isort] = sort(freq(ilist));
        j = ilist(isort);
        plot(freq(j), tau(j), clist{im}, 'linestyle', llist{m}, 'markerfacecolor', face{m});
        hold on;
    end;
    ylabel('Tau (ms)');
    xLabel('freq (Hz)')
    subplot(2,2,4);
    for i = 1: max(no)
        im = mod(i-1, max(no)-1)+1;
        ilist = find(no == i);
        m = find(strcmpi(CONTROL(sf(ilist(1))).CellType, uct));
        [x, isort] = sort(freq(ilist));
        j = ilist(isort);
        plot(freq(j), ssslow(j), clist{im}, 'linestyle', llist{m}, 'markerfacecolor', face{m});
        hold on;
    end;
    ylabel('Fraction ssSlow');
    xLabel('freq (Hz)')



cellstring = char(uct{:});

han = annotation(hf, 'textbox', [0, 0.9, 1, 0.095]);
set(han, 'String', CONTROL(sf(1)).CellType, 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle');
